package com.demo2do.fms.entity.driver;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import com.demo2do.core.format.PersistentFormat;
import com.demo2do.fms.entity.authority.Organization;
import com.demo2do.fms.entity.supplier.common.Supplier;
import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 车队信息
 *
 * @author Wy
 * @author zhonghui
 * 
 */
@Entity
@Table(name = "TBL_TRUCK_TEAM_INFO")
@PersistentFormat
public class Team {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    @SequenceGenerator(name = "generator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1)
    private Long id;

    /** 车队代码 */
    private String code;
    
    /** 车队名称 */
    private String name;

    /** 电话 */
    private String tel;

    /** 传真 */
    private String fax;

    /** 供应商 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @JoinColumn(name = "supplier_Id", referencedColumnName = "id")
    @JsonIgnore(value = true)
    @PersistentFormat
    private Supplier supplier;

    /** 部门负责人 */
    private String principalName;

    /** 公司名称 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @JoinColumn(name = "organization_Id", referencedColumnName = "id")
    @PersistentFormat
    private Organization organization;

    private Long creatorId;
    
    private Date createDate;
    
    private Long lastOperatorId;
    
    private Date lastModifyDate;

    @Column(name = "is_disabled")
    private Boolean disabled;
    
    /**
     * The default constructor
     */
    public Team() {
    }

    /**
     * 
     * @param disabled
     * @param operator
     * @return
     */
    public Team disable(boolean disabled, Long operator) {
        this.disabled = disabled;
        this.lastOperatorId = operator;
        this.lastModifyDate = new Date();
        return this;
    }

    /**
     * @param supplier
     * @param organizationId
     * @param operator
     * @return
     */
    public Team initialize(Supplier supplier, Long organizationId, Long operator) {

        this.supplier = supplier;
        if (organizationId != null) {
            this.organization = new Organization(organizationId);
        }
        
        this.creatorId = operator;
        this.createDate = new Date();
        this.lastOperatorId = operator;
        this.lastModifyDate = new Date();
        this.disabled = false;
        
        return this;
        
    }
    
    /**
     * @param lastOperatorId
     * @return
     */
    public Team operate(Long lastOperatorId) {
        this.lastOperatorId = lastOperatorId;
        this.lastModifyDate = new Date();
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return this.id;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return this.code;
    }

    /**
     * @return the name
     */
    public String getName() {
        return this.name;
    }

    /**
     * @return the tel
     */
    public String getTel() {
        return this.tel;
    }

    /**
     * @return the fax
     */
    public String getFax() {
        return this.fax;
    }

    /**
     * @return the principalName
     */
    public String getPrincipalName() {
        return this.principalName;
    }

    /**
     * @return the organization
     */
    public Organization getOrganization() {
        return organization;
    }

    /**
     * @return the createDate
     */
    public Date getCreateDate() {
        return this.createDate;
    }

    /**
     * @return the creatorId
     */
    public Long getCreatorId() {
        return this.creatorId;
    }

    /**
     * @return the lastModifyDate
     */
    public Date getLastModifyDate() {
        return this.lastModifyDate;
    }

    /**
     * @return the lastOperatorId
     */
    public Long getLastOperatorId() {
        return this.lastOperatorId;
    }

    /**
     * Gets supplier.
     *
     * @return the supplier
     */
    public Supplier getSupplier() {
        return supplier;
    }

    /**
     * @return the disabled
     */
    public Boolean getDisabled() {
        return this.disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param tel the tel to set
     */
    public void setTel(String tel) {
        this.tel = tel;
    }

    /**
     * @param fax the fax to set
     */
    public void setFax(String fax) {
        this.fax = fax;
    }

    /**
     * @param principalName the principalName to set
     */
    public void setPrincipalName(String principalName) {
        this.principalName = principalName;
    }

    /**
     * @param organization the organization to set
     */
    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    /**
     * @param createDate the createDate to set
     */
    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    /**
     * @param creatorId the creatorId to set
     */
    public void setCreatorId(Long creatorId) {
        this.creatorId = creatorId;
    }

    /**
     * @param lastModifyDate the lastModifyDate to set
     */
    public void setLastModifyDate(Date lastModifyDate) {
        this.lastModifyDate = lastModifyDate;
    }

    /**
     * @param lastOperatorId the lastOperatorId to set
     */
    public void setLastOperatorId(Long lastOperatorId) {
        this.lastOperatorId = lastOperatorId;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(Boolean disabled) {
        this.disabled = disabled;
    }


    /**
     * Sets supplier.
     *
     * @param supplier the supplier
     */
    public void setSupplier(Supplier supplier) {
        this.supplier = supplier;
    }
}
